<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>08_表单输入绑定</title>
</head>
<body>
<!--
1. 使用v-model(双向数据绑定)自动收集数据
  text/textarea：使用 value property 和 input 事件
  checkbox：使用 checked property 和 change 事件
  radio：使用 checked property 和 change 事件
  select：将 value 作为 prop 并将 change 作为事件

  修饰符：
    .lazy: 转为在 change 事件_之后_进行同步
    .number
    .trim: 自动过滤用户输入的首尾空白字符
-->
<div id="demo">
  <form action="/xxx" @submit.prevent="handleSubmit">
    <span>用户名: </span>
    <input type="text" v-model.lazy="username"><br>

    <span>密码: </span>
    <input type="password" v-model.trim="pwd"><br>

    <span>性别: </span>
    <input type="radio" id="female" value="女" v-model="sex"><label for="female">女</label>
    <input type="radio" id="male" value="男" v-model="sex"><label for="male">男</label><br>

    <span>爱好: </span>
    <input type="checkbox" id="basket" value="basket" v-model="likes">
    <label for="basket">篮球</label>
    <input type="checkbox" id="foot" value="foot" v-model="likes">
    <label for="foot">足球</label>
    <input type="checkbox" id="pingpang" value="pingpang" v-model="likes">
    <label for="pingpang">乒乓</label><br>

    <span>城市: </span>
    <select v-model="cityId">
      <option value="" disabled>未选择</option>
      <option :value="city.id" v-for="(city, index) in allCitys" :key="city.id" :disabled="city.disabled">{{city.name}}</option>
    </select><br>
    <span>介绍: </span>
    <textarea rows="10" v-model="info"></textarea><br><br>

    <input type="submit" value="注册">
  </form>
</div>

<script type="text/javascript" src="../public/cdn/vue/2.6.10/vue.min.js"></script>
<script type="text/javascript">
  new Vue({
    el: '#demo',
    data: {
      username: '姓名',
      pwd: '密码',
      sex: '男',
      likes: ['foot','pingpang'],
      allCitys: [{id: 1, name: 'BJ'}, {id: 2, name: 'SS', disabled: true}, {id: 3, name: 'SZ'}],
      cityId: '3',
      info: 'this is my info'
    },
    methods: {
      handleSubmit () {
        console.log(this.username, this.pwd, this.sex, this.likes, this.cityId, this.info)
        alert('提交注册的ajax请求')
      }
    }
  })
</script>
</body>
</html>